#include "request-server.hh"

ConnectionServer::ConnectionServer (const std::string& data):
  login_ (),
  pwd_ (),
  flag_ ()
{
  size_t pos = data.find (' ');

  if (pos == std::string::npos)
  {
    flag_ = "WRONGINPUT";
  }
  else
  {
    login_ = data.substr (0, pos);
    pwd_ = data.substr (pos + 1, std::string::npos);
  }
}

bool
ConnectionServer::identification (Database* db)
{
  if (!flag_.empty ())
    return false;

  PlayerInfo* pi = db->find_player (login_);

  if (!pi)
  {
    flag_ = "NOLOGIN";
    return false;
  }

  if (pi->pass_get () != pwd_)
  {
    flag_ = "BADPWD";
    return false;
  }

  flag_ = "OK";
  return true;
}

GetObjectServer::GetObjectServer (const std::string& data):
  objectid_ (Utility::from_oct (data.data ()))
{
}

ReadyServer::ReadyServer (boost::shared_ptr<Client> c):
  c_ (c)
{
}
